<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>分类: 技术教程 | 小小程序员</title><meta name="author" content="十一星野"><meta name="copyright" content="十一星野"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="本文主要讲解 mall 整合 OSS 实现文件上传的过程，采用的是服务端签名后前端直传的方式。  #👍 相关视频教程mall整合MinIO实现文件上传open in new window #MinIOmall项目能同时支持OSS和MinIO两种对象存储，如果想使用MinIO实现文件存储，可以参考如下文章。  MinIO使用教程 前后端分离项目使用MinIO实现文件存储  #OSS 阿里云对象存">
<meta property="og:type" content="article">
<meta property="og:title" content="mall整合OSS实现文件上传">
<meta property="og:url" content="https://ko25891wan.gitlab.io/2024/01/9193a72ed815.html">
<meta property="og:site_name" content="小小程序员">
<meta property="og:description" content="本文主要讲解 mall 整合 OSS 实现文件上传的过程，采用的是服务端签名后前端直传的方式。  #👍 相关视频教程mall整合MinIO实现文件上传open in new window #MinIOmall项目能同时支持OSS和MinIO两种对象存储，如果想使用MinIO实现文件存储，可以参考如下文章。  MinIO使用教程 前后端分离项目使用MinIO实现文件存储  #OSS 阿里云对象存">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/%E5%A4%B4%E5%83%8F/%E7%81%B0%E5%A4%AA%E7%8B%BC.png">
<meta property="article:published_time" content="2024-01-21T09:27:12.000Z">
<meta property="article:modified_time" content="2024-02-02T15:07:39.266Z">
<meta property="article:author" content="十一星野">
<meta property="article:tag" content="宅男,热血">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/%E5%A4%B4%E5%83%8F/%E7%81%B0%E5%A4%AA%E7%8B%BC.png"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://ko25891wan.gitlab.io/2024/01/9193a72ed815.html"><link rel="preconnect" href="//fastly.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.5.1/css/all.min.css"><link rel="stylesheet" href="https://cdn.staticfile.org/fancyapps-ui/5.0.32/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":false,"top_n_per_article":1,"unescape":false,"languages":{"hits_empty":"找不到您查询的内容：${query}","hits_stats":"共找到 ${hits} 篇文章"}},
  translate: {"defaultEncoding":1,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"简"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlight.js","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":200},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: true,
    post: true
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  infinitegrid: {
    js: 'https://cdn.staticfile.org/egjs-infinitegrid/4.11.0/infinitegrid.min.js',
    buttonText: '加载更多'
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: true,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '分类: 技术教程',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2024-02-02 23:07:39'
}</script><script>(win=>{
      win.saveToLocal = {
        set: (key, value, ttl) => {
          if (ttl === 0) return
          const now = Date.now()
          const expiry = now + ttl * 86400000
          const item = {
            value,
            expiry
          }
          localStorage.setItem(key, JSON.stringify(item))
        },
      
        get: key => {
          const itemStr = localStorage.getItem(key)
      
          if (!itemStr) {
            return undefined
          }
          const item = JSON.parse(itemStr)
          const now = Date.now()
      
          if (now > item.expiry) {
            localStorage.removeItem(key)
            return undefined
          }
          return item.value
        }
      }
    
      win.getScript = (url, attr = {}) => new Promise((resolve, reject) => {
        const script = document.createElement('script')
        script.src = url
        script.async = true
        script.onerror = reject
        script.onload = script.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          script.onload = script.onreadystatechange = null
          resolve()
        }

        Object.keys(attr).forEach(key => {
          script.setAttribute(key, attr[key])
        })

        document.head.appendChild(script)
      })
    
      win.getCSS = (url, id = false) => new Promise((resolve, reject) => {
        const link = document.createElement('link')
        link.rel = 'stylesheet'
        link.href = url
        if (id) link.id = id
        link.onerror = reject
        link.onload = link.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          link.onload = link.onreadystatechange = null
          resolve()
        }
        document.head.appendChild(link)
      })
    
      win.activateDarkMode = () => {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = () => {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
        if (t === 'dark') activateDarkMode()
        else if (t === 'light') activateLightMode()
      
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
      const detectApple = () => {
        if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
          document.documentElement.classList.add('apple')
        }
      }
      detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>(()=>{
  const $loadingBox = document.getElementById('loading-box')
  const $body = document.body
  const preloader = {
    endLoading: () => {
      $body.style.overflow = ''
      $loadingBox.classList.add('loaded')
    },
    initLoading: () => {
      $body.style.overflow = 'hidden'
      $loadingBox.classList.remove('loaded')
    }
  }

  preloader.initLoading()
  window.addEventListener('load',() => { preloader.endLoading() })

  if (false) {
    document.addEventListener('pjax:send', () => { preloader.initLoading() })
    document.addEventListener('pjax:complete', () => { preloader.endLoading() })
  }
})()</script><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/%E5%A4%B4%E5%83%8F/%E7%81%B0%E5%A4%AA%E7%8B%BC.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">120</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">4</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">22</div></a></div><hr class="custom-hr"/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-heartbeat"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-tools"></i><span> 工具</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/md_editor/"><i class="fa-fw fas fa-pen"></i><span> MDEditor_my</span></a></li></ul></div></div></div></div><div class="post" id="body-wrap"><header class="not-top-img" id="page-header"><nav id="nav"><span id="blog-info"><a href="/" title="小小程序员"><span class="site-name">小小程序员</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-heartbeat"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-tools"></i><span> 工具</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/md_editor/"><i class="fa-fw fas fa-pen"></i><span> MDEditor_my</span></a></li></ul></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav></header><main class="layout" id="content-inner"><div id="post"><div id="post-info"><h1 class="post-title">mall整合OSS实现文件上传</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2024-01-21T09:27:12.000Z" title="发表于 2024-01-21 17:27:12">2024-01-21</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2024-02-02T15:07:39.266Z" title="更新于 2024-02-02 23:07:39">2024-02-02</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%8A%80%E6%9C%AF%E6%95%99%E7%A8%8B/">技术教程</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%8A%80%E6%9C%AF%E6%95%99%E7%A8%8B/mall/">mall</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%8A%80%E6%9C%AF%E6%95%99%E7%A8%8B/mall/%E6%9E%B6%E6%9E%84%E7%AF%87/">架构篇</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">2.5k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>11分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="mall整合OSS实现文件上传"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div><article class="post-content" id="article-container"><blockquote>
<p>本文主要讲解 mall 整合 OSS 实现文件上传的过程，采用的是服务端签名后前端直传的方式。</p>
</blockquote>
<h2 id="👍-相关视频教程"><a href="#👍-相关视频教程" class="headerlink" title="#👍 相关视频教程"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_10.html#%F0%9F%91%8D-%E7%9B%B8%E5%85%B3%E8%A7%86%E9%A2%91%E6%95%99%E7%A8%8B">#</a>👍 相关视频教程</h2><p><a target="_blank" rel="noopener" href="https://t.zsxq.com/0eo1vfFee">mall整合MinIO实现文件上传open in new window</a></p>
<h2 id="MinIO"><a href="#MinIO" class="headerlink" title="#MinIO"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_10.html#minio">#</a>MinIO</h2><p>mall项目能同时支持OSS和MinIO两种对象存储，如果想使用MinIO实现文件存储，可以参考如下文章。</p>
<ul>
<li><a target="_blank" rel="noopener" href="https://www.macrozheng.com/project/minio_console_start.html">MinIO使用教程</a></li>
<li><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/technology/minio_use.html">前后端分离项目使用MinIO实现文件存储</a></li>
</ul>
<h2 id="OSS"><a href="#OSS" class="headerlink" title="#OSS"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_10.html#oss">#</a>OSS</h2><blockquote>
<p>阿里云对象存储服务（Object Storage Service，简称 OSS），是阿里云提供的海量、安全、低成本、高可靠的云存储服务。OSS可用于图片、音视频、日志等海量文件的存储。各种终端设备、Web网站程序、移动应用可以直接向OSS写入或读取数据。</p>
</blockquote>
<h3 id="OSS中的相关概念"><a href="#OSS中的相关概念" class="headerlink" title="#OSS中的相关概念"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_10.html#oss%E4%B8%AD%E7%9A%84%E7%9B%B8%E5%85%B3%E6%A6%82%E5%BF%B5">#</a>OSS中的相关概念</h3><ul>
<li>Endpoint：访问域名，通过该域名可以访问OSS服务的API，进行文件上传、下载等操作。</li>
<li>Bucket：存储空间，是存储对象的容器，所有存储对象都必须隶属于某个存储空间。</li>
<li>Object：对象，对象是 OSS 存储数据的基本单元，也被称为 OSS 的文件。</li>
<li>AccessKey：访问密钥，指的是访问身份验证中用到的 AccessKeyId 和 AccessKeySecret。</li>
</ul>
<h3 id="OSS的相关设置"><a href="#OSS的相关设置" class="headerlink" title="#OSS的相关设置"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_10.html#oss%E7%9A%84%E7%9B%B8%E5%85%B3%E8%AE%BE%E7%BD%AE">#</a>OSS的相关设置</h3><h4 id="开通OSS服务"><a href="#开通OSS服务" class="headerlink" title="#开通OSS服务"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_10.html#%E5%BC%80%E9%80%9Aoss%E6%9C%8D%E5%8A%A1">#</a>开通OSS服务</h4><ul>
<li>登录阿里云官网；</li>
<li>将鼠标移至产品标签页，单击对象存储 OSS，打开OSS 产品详情页面；</li>
<li>在OSS产品详情页，单击立即开通。</li>
</ul>
<h4 id="创建存储空间"><a href="#创建存储空间" class="headerlink" title="#创建存储空间"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_10.html#%E5%88%9B%E5%BB%BA%E5%AD%98%E5%82%A8%E7%A9%BA%E9%97%B4">#</a>创建存储空间</h4><ul>
<li>点击网页右上角控制台按钮进入控制台</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-02_23:07:10_arch_screen_77-d6080613.png"></p>
<ul>
<li>选择我的云产品中的对象存储OSS</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-02_23:07:10_arch_screen_78-4945e92c.png"></p>
<ul>
<li>点击左侧存储空间的加号新建存储空间</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-02_23:07:10_arch_screen_79-cb239737.png"></p>
<ul>
<li>新建存储空间并设置读写权限为公共读</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-02_23:07:10_arch_screen_80-9dde6423.png"></p>
<h4 id="跨域资源共享（CORS）的设置"><a href="#跨域资源共享（CORS）的设置" class="headerlink" title="#跨域资源共享（CORS）的设置"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_10.html#%E8%B7%A8%E5%9F%9F%E8%B5%84%E6%BA%90%E5%85%B1%E4%BA%AB-cors-%E7%9A%84%E8%AE%BE%E7%BD%AE">#</a>跨域资源共享（CORS）的设置</h4><blockquote>
<p>由于浏览器处于安全考虑，不允许跨域资源访问，所以我们要设置OSS的跨域资源共享。</p>
</blockquote>
<ul>
<li>选择一个存储空间，打开其基础设置</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-02_23:07:10_arch_screen_81-f9b45016.png"></p>
<ul>
<li>点击跨越设置的设置按钮</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-02_23:07:10_arch_screen_82-925a8c9e.png"></p>
<ul>
<li>点击创建规则</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-02_23:07:10_arch_screen_83-1ec0b32b.png"></p>
<ul>
<li>进行跨域规则设置</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-02_23:07:10_arch_screen_84-5cfeaa04.png"></p>
<h3 id="服务端签名后前端直传的相关说明"><a href="#服务端签名后前端直传的相关说明" class="headerlink" title="#服务端签名后前端直传的相关说明"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_10.html#%E6%9C%8D%E5%8A%A1%E7%AB%AF%E7%AD%BE%E5%90%8D%E5%90%8E%E5%89%8D%E7%AB%AF%E7%9B%B4%E4%BC%A0%E7%9A%84%E7%9B%B8%E5%85%B3%E8%AF%B4%E6%98%8E">#</a>服务端签名后前端直传的相关说明</h3><h4 id="流程示例图"><a href="#流程示例图" class="headerlink" title="#流程示例图"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_10.html#%E6%B5%81%E7%A8%8B%E7%A4%BA%E4%BE%8B%E5%9B%BE">#</a>流程示例图</h4><p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-02_23:07:10_arch_screen_85-4e9853ba.png"></p>
<h4 id="流程介绍"><a href="#流程介绍" class="headerlink" title="#流程介绍"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_10.html#%E6%B5%81%E7%A8%8B%E4%BB%8B%E7%BB%8D">#</a>流程介绍</h4><ol>
<li>Web前端请求应用服务器，获取上传所需参数（如OSS的accessKeyId、policy、callback等参数）</li>
<li>应用服务器返回相关参数</li>
<li>Web前端直接向OSS服务发起上传文件请求</li>
<li>等上传完成后OSS服务会回调应用服务器的回调接口</li>
<li>应用服务器返回响应给OSS服务</li>
<li>OSS服务将应用服务器回调接口的内容返回给Web前端</li>
</ol>
<h2 id="整合OSS实现文件上传"><a href="#整合OSS实现文件上传" class="headerlink" title="#整合OSS实现文件上传"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_10.html#%E6%95%B4%E5%90%88oss%E5%AE%9E%E7%8E%B0%E6%96%87%E4%BB%B6%E4%B8%8A%E4%BC%A0">#</a>整合OSS实现文件上传</h2><h3 id="在pom-xml中添加相关依赖"><a href="#在pom-xml中添加相关依赖" class="headerlink" title="#在pom.xml中添加相关依赖"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_10.html#%E5%9C%A8pom-xml%E4%B8%AD%E6%B7%BB%E5%8A%A0%E7%9B%B8%E5%85%B3%E4%BE%9D%E8%B5%96">#</a>在pom.xml中添加相关依赖</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">&lt;!-- OSS SDK 相关依赖 --&gt;</span><br><span class="line">&lt;dependency&gt;</span><br><span class="line">    &lt;groupId&gt;com.aliyun.oss&lt;/groupId&gt;</span><br><span class="line">    &lt;artifactId&gt;aliyun-sdk-oss&lt;/artifactId&gt;</span><br><span class="line">    &lt;version&gt;2.5.0&lt;/version&gt;</span><br><span class="line">&lt;/dependency&gt;</span><br></pre></td></tr></table></figure>

<h3 id="修改SpringBoot配置文件"><a href="#修改SpringBoot配置文件" class="headerlink" title="#修改SpringBoot配置文件"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_10.html#%E4%BF%AE%E6%94%B9springboot%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6">#</a>修改SpringBoot配置文件</h3><blockquote>
<p>修改application.yml文件，添加OSS相关配置。</p>
</blockquote>
<p>注意：endpoint、accessKeyId、accessKeySecret、bucketName、callback、prefix都要改为你自己帐号OSS相关的，callback需要是公网可以访问的地址。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"># OSS相关配置信息</span><br><span class="line">aliyun:</span><br><span class="line">  oss:</span><br><span class="line">    endpoint: oss-cn-shenzhen.aliyuncs.com # oss对外服务的访问域名</span><br><span class="line">    accessKeyId: test # 访问身份验证中用到用户标识</span><br><span class="line">    accessKeySecret: test # 用户用于加密签名字符串和oss用来验证签名字符串的密钥</span><br><span class="line">    bucketName: macro-oss # oss的存储空间</span><br><span class="line">    policy:</span><br><span class="line">      expire: 300 # 签名有效期(S)</span><br><span class="line">    maxSize: 10 # 上传文件大小(M)</span><br><span class="line">    callback: http://localhost:8080/aliyun/oss/callback # 文件上传成功后的回调地址</span><br><span class="line">    dir:</span><br><span class="line">      prefix: mall/images/ # 上传文件夹路径前缀</span><br></pre></td></tr></table></figure>

<h3 id="添加OSS的相关Java配置"><a href="#添加OSS的相关Java配置" class="headerlink" title="#添加OSS的相关Java配置"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_10.html#%E6%B7%BB%E5%8A%A0oss%E7%9A%84%E7%9B%B8%E5%85%B3java%E9%85%8D%E7%BD%AE">#</a>添加OSS的相关Java配置</h3><blockquote>
<p>用于配置OSS的连接客户端OSSClient。</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">package com.macro.mall.tiny.config;</span><br><span class="line"></span><br><span class="line">import com.aliyun.oss.OSSClient;</span><br><span class="line">import org.springframework.beans.factory.annotation.Value;</span><br><span class="line">import org.springframework.context.annotation.Bean;</span><br><span class="line">import org.springframework.context.annotation.Configuration;</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * Created by macro on 2018/5/17.</span><br><span class="line"> */</span><br><span class="line">@Configuration</span><br><span class="line">public class OssConfig &#123;</span><br><span class="line">    @Value(&quot;$&#123;aliyun.oss.endpoint&#125;&quot;)</span><br><span class="line">    private String ALIYUN_OSS_ENDPOINT;</span><br><span class="line">    @Value(&quot;$&#123;aliyun.oss.accessKeyId&#125;&quot;)</span><br><span class="line">    private String ALIYUN_OSS_ACCESSKEYID;</span><br><span class="line">    @Value(&quot;$&#123;aliyun.oss.accessKeySecret&#125;&quot;)</span><br><span class="line">    private String ALIYUN_OSS_ACCESSKEYSECRET;</span><br><span class="line">    @Bean</span><br><span class="line">    public OSSClient ossClient()&#123;</span><br><span class="line">        return new OSSClient(ALIYUN_OSS_ENDPOINT,ALIYUN_OSS_ACCESSKEYID,ALIYUN_OSS_ACCESSKEYSECRET);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="添加OSS上传策略封装对象OssPolicyResult"><a href="#添加OSS上传策略封装对象OssPolicyResult" class="headerlink" title="#添加OSS上传策略封装对象OssPolicyResult"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_10.html#%E6%B7%BB%E5%8A%A0oss%E4%B8%8A%E4%BC%A0%E7%AD%96%E7%95%A5%E5%B0%81%E8%A3%85%E5%AF%B9%E8%B1%A1osspolicyresult">#</a>添加OSS上传策略封装对象OssPolicyResult</h3><blockquote>
<p>前端直接上传文件时所需参数，从后端返回过来。</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">package com.macro.mall.tiny.dto;</span><br><span class="line"></span><br><span class="line">import io.swagger.annotations.ApiModelProperty;</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * 获取OSS上传文件授权返回结果</span><br><span class="line"> * Created by macro on 2018/5/17.</span><br><span class="line"> */</span><br><span class="line">public class OssPolicyResult &#123;</span><br><span class="line">    @ApiModelProperty(&quot;访问身份验证中用到用户标识&quot;)</span><br><span class="line">    private String accessKeyId;</span><br><span class="line">    @ApiModelProperty(&quot;用户表单上传的策略,经过base64编码过的字符串&quot;)</span><br><span class="line">    private String policy;</span><br><span class="line">    @ApiModelProperty(&quot;对policy签名后的字符串&quot;)</span><br><span class="line">    private String signature;</span><br><span class="line">    @ApiModelProperty(&quot;上传文件夹路径前缀&quot;)</span><br><span class="line">    private String dir;</span><br><span class="line">    @ApiModelProperty(&quot;oss对外服务的访问域名&quot;)</span><br><span class="line">    private String host;</span><br><span class="line">    @ApiModelProperty(&quot;上传成功后的回调设置&quot;)</span><br><span class="line">    private String callback;</span><br><span class="line"></span><br><span class="line">    //省略了所有getter,setter方法</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="添加OSS上传成功后的回调参数对象OssCallbackParam"><a href="#添加OSS上传成功后的回调参数对象OssCallbackParam" class="headerlink" title="#添加OSS上传成功后的回调参数对象OssCallbackParam"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_10.html#%E6%B7%BB%E5%8A%A0oss%E4%B8%8A%E4%BC%A0%E6%88%90%E5%8A%9F%E5%90%8E%E7%9A%84%E5%9B%9E%E8%B0%83%E5%8F%82%E6%95%B0%E5%AF%B9%E8%B1%A1osscallbackparam">#</a>添加OSS上传成功后的回调参数对象OssCallbackParam</h3><blockquote>
<p>当OSS上传成功后，会根据该配置参数来回调对应接口。</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">package com.macro.mall.tiny.dto;</span><br><span class="line"></span><br><span class="line">import io.swagger.annotations.ApiModelProperty;</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * oss上传成功后的回调参数</span><br><span class="line"> * Created by macro on 2018/5/17.</span><br><span class="line"> */</span><br><span class="line">public class OssCallbackParam &#123;</span><br><span class="line">    @ApiModelProperty(&quot;请求的回调地址&quot;)</span><br><span class="line">    private String callbackUrl;</span><br><span class="line">    @ApiModelProperty(&quot;回调是传入request中的参数&quot;)</span><br><span class="line">    private String callbackBody;</span><br><span class="line">    @ApiModelProperty(&quot;回调时传入参数的格式，比如表单提交形式&quot;)</span><br><span class="line">    private String callbackBodyType;</span><br><span class="line"></span><br><span class="line">    //省略了所有getter,setter方法</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="OSS上传成功后的回调结果对象OssCallbackResult"><a href="#OSS上传成功后的回调结果对象OssCallbackResult" class="headerlink" title="#OSS上传成功后的回调结果对象OssCallbackResult"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_10.html#oss%E4%B8%8A%E4%BC%A0%E6%88%90%E5%8A%9F%E5%90%8E%E7%9A%84%E5%9B%9E%E8%B0%83%E7%BB%93%E6%9E%9C%E5%AF%B9%E8%B1%A1osscallbackresult">#</a>OSS上传成功后的回调结果对象OssCallbackResult</h3><blockquote>
<p>回调接口中返回的数据对象，封装了上传文件的信息。</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">package com.macro.mall.tiny.dto;</span><br><span class="line"></span><br><span class="line">import io.swagger.annotations.ApiModelProperty;</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * oss上传文件的回调结果</span><br><span class="line"> * Created by macro on 2018/5/17.</span><br><span class="line"> */</span><br><span class="line">public class OssCallbackResult &#123;</span><br><span class="line">    @ApiModelProperty(&quot;文件名称&quot;)</span><br><span class="line">    private String filename;</span><br><span class="line">    @ApiModelProperty(&quot;文件大小&quot;)</span><br><span class="line">    private String size;</span><br><span class="line">    @ApiModelProperty(&quot;文件的mimeType&quot;)</span><br><span class="line">    private String mimeType;</span><br><span class="line">    @ApiModelProperty(&quot;图片文件的宽&quot;)</span><br><span class="line">    private String width;</span><br><span class="line">    @ApiModelProperty(&quot;图片文件的高&quot;)</span><br><span class="line">    private String height;</span><br><span class="line"></span><br><span class="line">    //省略了所有getter,setter方法</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="添加OSS业务接口OssService"><a href="#添加OSS业务接口OssService" class="headerlink" title="#添加OSS业务接口OssService"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_10.html#%E6%B7%BB%E5%8A%A0oss%E4%B8%9A%E5%8A%A1%E6%8E%A5%E5%8F%A3ossservice">#</a>添加OSS业务接口OssService</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">package com.macro.mall.tiny.service;</span><br><span class="line"></span><br><span class="line">import com.macro.mall.tiny.dto.OssCallbackResult;</span><br><span class="line">import com.macro.mall.tiny.dto.OssPolicyResult;</span><br><span class="line"></span><br><span class="line">import javax.servlet.http.HttpServletRequest;</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * oss上传管理Service</span><br><span class="line"> * Created by macro on 2018/5/17.</span><br><span class="line"> */</span><br><span class="line">public interface OssService &#123;</span><br><span class="line">    /**</span><br><span class="line">     * oss上传策略生成</span><br><span class="line">     */</span><br><span class="line">    OssPolicyResult policy();</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * oss上传成功回调</span><br><span class="line">     */</span><br><span class="line">    OssCallbackResult callback(HttpServletRequest request);</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="添加OSS业务接口OssService的实现类OssServiceImpl"><a href="#添加OSS业务接口OssService的实现类OssServiceImpl" class="headerlink" title="#添加OSS业务接口OssService的实现类OssServiceImpl"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_10.html#%E6%B7%BB%E5%8A%A0oss%E4%B8%9A%E5%8A%A1%E6%8E%A5%E5%8F%A3ossservice%E7%9A%84%E5%AE%9E%E7%8E%B0%E7%B1%BBossserviceimpl">#</a>添加OSS业务接口OssService的实现类OssServiceImpl</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br></pre></td><td class="code"><pre><span class="line">package com.macro.mall.tiny.service.impl;</span><br><span class="line"></span><br><span class="line">import cn.hutool.json.JSONUtil;</span><br><span class="line">import com.aliyun.oss.OSSClient;</span><br><span class="line">import com.aliyun.oss.common.utils.BinaryUtil;</span><br><span class="line">import com.aliyun.oss.model.MatchMode;</span><br><span class="line">import com.aliyun.oss.model.PolicyConditions;</span><br><span class="line">import com.macro.mall.tiny.dto.OssCallbackParam;</span><br><span class="line">import com.macro.mall.tiny.dto.OssCallbackResult;</span><br><span class="line">import com.macro.mall.tiny.dto.OssPolicyResult;</span><br><span class="line">import com.macro.mall.tiny.service.OssService;</span><br><span class="line">import org.slf4j.Logger;</span><br><span class="line">import org.slf4j.LoggerFactory;</span><br><span class="line">import org.springframework.beans.factory.annotation.Autowired;</span><br><span class="line">import org.springframework.beans.factory.annotation.Value;</span><br><span class="line">import org.springframework.stereotype.Service;</span><br><span class="line"></span><br><span class="line">import javax.servlet.http.HttpServletRequest;</span><br><span class="line">import java.text.SimpleDateFormat;</span><br><span class="line">import java.util.Date;</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * oss上传管理Service实现类</span><br><span class="line"> * Created by macro on 2018/5/17.</span><br><span class="line"> */</span><br><span class="line">@Service</span><br><span class="line">public class OssServiceImpl implements OssService &#123;</span><br><span class="line"></span><br><span class="line">	private static final Logger LOGGER = LoggerFactory.getLogger(OssServiceImpl.class);</span><br><span class="line">	@Value(&quot;$&#123;aliyun.oss.policy.expire&#125;&quot;)</span><br><span class="line">	private int ALIYUN_OSS_EXPIRE;</span><br><span class="line">	@Value(&quot;$&#123;aliyun.oss.maxSize&#125;&quot;)</span><br><span class="line">	private int ALIYUN_OSS_MAX_SIZE;</span><br><span class="line">	@Value(&quot;$&#123;aliyun.oss.callback&#125;&quot;)</span><br><span class="line">	private String ALIYUN_OSS_CALLBACK;</span><br><span class="line">	@Value(&quot;$&#123;aliyun.oss.bucketName&#125;&quot;)</span><br><span class="line">	private String ALIYUN_OSS_BUCKET_NAME;</span><br><span class="line">	@Value(&quot;$&#123;aliyun.oss.endpoint&#125;&quot;)</span><br><span class="line">	private String ALIYUN_OSS_ENDPOINT;</span><br><span class="line">	@Value(&quot;$&#123;aliyun.oss.dir.prefix&#125;&quot;)</span><br><span class="line">	private String ALIYUN_OSS_DIR_PREFIX;</span><br><span class="line"></span><br><span class="line">	@Autowired</span><br><span class="line">	private OSSClient ossClient;</span><br><span class="line"></span><br><span class="line">	/**</span><br><span class="line">	 * 签名生成</span><br><span class="line">	 */</span><br><span class="line">	@Override</span><br><span class="line">	public OssPolicyResult policy() &#123;</span><br><span class="line">		OssPolicyResult result = new OssPolicyResult();</span><br><span class="line">		// 存储目录</span><br><span class="line">		SimpleDateFormat sdf = new SimpleDateFormat(&quot;yyyyMMdd&quot;);</span><br><span class="line">		String dir = ALIYUN_OSS_DIR_PREFIX+sdf.format(new Date());</span><br><span class="line">		// 签名有效期</span><br><span class="line">		long expireEndTime = System.currentTimeMillis() + ALIYUN_OSS_EXPIRE * 1000;</span><br><span class="line">		Date expiration = new Date(expireEndTime);</span><br><span class="line">		// 文件大小</span><br><span class="line">		long maxSize = ALIYUN_OSS_MAX_SIZE * 1024 * 1024;</span><br><span class="line">		// 回调</span><br><span class="line">		OssCallbackParam callback = new OssCallbackParam();</span><br><span class="line">		callback.setCallbackUrl(ALIYUN_OSS_CALLBACK);</span><br><span class="line">		callback.setCallbackBody(&quot;filename=$&#123;object&#125;&amp;size=$&#123;size&#125;&amp;mimeType=$&#123;mimeType&#125;&amp;height=$&#123;imageInfo.height&#125;&amp;width=$&#123;imageInfo.width&#125;&quot;);</span><br><span class="line">		callback.setCallbackBodyType(&quot;application/x-www-form-urlencoded&quot;);</span><br><span class="line">		// 提交节点</span><br><span class="line">		String action = &quot;http://&quot; + ALIYUN_OSS_BUCKET_NAME + &quot;.&quot; + ALIYUN_OSS_ENDPOINT;</span><br><span class="line">		try &#123;</span><br><span class="line">			PolicyConditions policyConds = new PolicyConditions();</span><br><span class="line">			policyConds.addConditionItem(PolicyConditions.COND_CONTENT_LENGTH_RANGE, 0, maxSize);</span><br><span class="line">			policyConds.addConditionItem(MatchMode.StartWith, PolicyConditions.COND_KEY, dir);</span><br><span class="line">			String postPolicy = ossClient.generatePostPolicy(expiration, policyConds);</span><br><span class="line">			byte[] binaryData = postPolicy.getBytes(&quot;utf-8&quot;);</span><br><span class="line">			String policy = BinaryUtil.toBase64String(binaryData);</span><br><span class="line">			String signature = ossClient.calculatePostSignature(postPolicy);</span><br><span class="line">			String callbackData = BinaryUtil.toBase64String(JSONUtil.parse(callback).toString().getBytes(&quot;utf-8&quot;));</span><br><span class="line">			// 返回结果</span><br><span class="line">			result.setAccessKeyId(ossClient.getCredentialsProvider().getCredentials().getAccessKeyId());</span><br><span class="line">			result.setPolicy(policy);</span><br><span class="line">			result.setSignature(signature);</span><br><span class="line">			result.setDir(dir);</span><br><span class="line">			result.setCallback(callbackData);</span><br><span class="line">			result.setHost(action);</span><br><span class="line">		&#125; catch (Exception e) &#123;</span><br><span class="line">			LOGGER.error(&quot;签名生成失败&quot;, e);</span><br><span class="line">		&#125;</span><br><span class="line">		return result;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	@Override</span><br><span class="line">	public OssCallbackResult callback(HttpServletRequest request) &#123;</span><br><span class="line">		OssCallbackResult result= new OssCallbackResult();</span><br><span class="line">		String filename = request.getParameter(&quot;filename&quot;);</span><br><span class="line">		filename = &quot;http://&quot;.concat(ALIYUN_OSS_BUCKET_NAME).concat(&quot;.&quot;).concat(ALIYUN_OSS_ENDPOINT).concat(&quot;/&quot;).concat(filename);</span><br><span class="line">		result.setFilename(filename);</span><br><span class="line">		result.setSize(request.getParameter(&quot;size&quot;));</span><br><span class="line">		result.setMimeType(request.getParameter(&quot;mimeType&quot;));</span><br><span class="line">		result.setWidth(request.getParameter(&quot;width&quot;));</span><br><span class="line">		result.setHeight(request.getParameter(&quot;height&quot;));</span><br><span class="line">		return result;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="添加OssController定义接口"><a href="#添加OssController定义接口" class="headerlink" title="#添加OssController定义接口"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_10.html#%E6%B7%BB%E5%8A%A0osscontroller%E5%AE%9A%E4%B9%89%E6%8E%A5%E5%8F%A3">#</a>添加OssController定义接口</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line">package com.macro.mall.tiny.controller;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">import com.macro.mall.tiny.common.api.CommonResult;</span><br><span class="line">import com.macro.mall.tiny.dto.OssCallbackResult;</span><br><span class="line">import com.macro.mall.tiny.dto.OssPolicyResult;</span><br><span class="line">import com.macro.mall.tiny.service.impl.OssServiceImpl;</span><br><span class="line">import io.swagger.annotations.Api;</span><br><span class="line">import io.swagger.annotations.ApiOperation;</span><br><span class="line">import org.springframework.beans.factory.annotation.Autowired;</span><br><span class="line">import org.springframework.stereotype.Controller;</span><br><span class="line">import org.springframework.web.bind.annotation.RequestMapping;</span><br><span class="line">import org.springframework.web.bind.annotation.RequestMethod;</span><br><span class="line">import org.springframework.web.bind.annotation.ResponseBody;</span><br><span class="line"></span><br><span class="line">import javax.servlet.http.HttpServletRequest;</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * Oss相关操作接口</span><br><span class="line"> * Created by macro on 2018/4/26.</span><br><span class="line"> */</span><br><span class="line">@Controller</span><br><span class="line">@Api(tags = &quot;OssController&quot;, description = &quot;Oss管理&quot;)</span><br><span class="line">@RequestMapping(&quot;/aliyun/oss&quot;)</span><br><span class="line">public class OssController &#123;</span><br><span class="line">    @Autowired</span><br><span class="line">    private OssServiceImpl ossService;</span><br><span class="line"></span><br><span class="line">    @ApiOperation(value = &quot;oss上传签名生成&quot;)</span><br><span class="line">    @RequestMapping(value = &quot;/policy&quot;, method = RequestMethod.GET)</span><br><span class="line">    @ResponseBody</span><br><span class="line">    public CommonResult&lt;OssPolicyResult&gt; policy() &#123;</span><br><span class="line">        OssPolicyResult result = ossService.policy();</span><br><span class="line">        return CommonResult.success(result);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @ApiOperation(value = &quot;oss上传成功回调&quot;)</span><br><span class="line">    @RequestMapping(value = &quot;callback&quot;, method = RequestMethod.POST)</span><br><span class="line">    @ResponseBody</span><br><span class="line">    public CommonResult&lt;OssCallbackResult&gt; callback(HttpServletRequest request) &#123;</span><br><span class="line">        OssCallbackResult ossCallbackResult = ossService.callback(request);</span><br><span class="line">        return CommonResult.success(ossCallbackResult);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="进行接口测试"><a href="#进行接口测试" class="headerlink" title="#进行接口测试"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_10.html#%E8%BF%9B%E8%A1%8C%E6%8E%A5%E5%8F%A3%E6%B5%8B%E8%AF%95">#</a>进行接口测试</h2><h3 id="测试获取上传策略的接口"><a href="#测试获取上传策略的接口" class="headerlink" title="#测试获取上传策略的接口"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_10.html#%E6%B5%8B%E8%AF%95%E8%8E%B7%E5%8F%96%E4%B8%8A%E4%BC%A0%E7%AD%96%E7%95%A5%E7%9A%84%E6%8E%A5%E5%8F%A3">#</a>测试获取上传策略的接口</h3><p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-02_23:07:10_arch_screen_66-55d29bc0.png"></p>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-02_23:07:10_arch_screen_67-305916c4.png"></p>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-02_23:07:10_arch_screen_68-08b7da45.png"></p>
<h3 id="启动mall-admin-web前端项目来测试上传接口"><a href="#启动mall-admin-web前端项目来测试上传接口" class="headerlink" title="#启动mall-admin-web前端项目来测试上传接口"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_10.html#%E5%90%AF%E5%8A%A8mall-admin-web%E5%89%8D%E7%AB%AF%E9%A1%B9%E7%9B%AE%E6%9D%A5%E6%B5%8B%E8%AF%95%E4%B8%8A%E4%BC%A0%E6%8E%A5%E5%8F%A3">#</a>启动mall-admin-web前端项目来测试上传接口</h3><ul>
<li><p>如何启动前端项目，具体参考该项目的readme文档：<a target="_blank" rel="noopener" href="https://github.com/macrozheng/mall-admin-web">https://github.com/macrozheng/mall-admin-webopen in new window</a></p>
</li>
<li><p>点击添加商品品牌的上传按钮进行测试</p>
</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-02_23:07:10_arch_screen_69-66c9fbb7.png"></p>
<ul>
<li>会调用两次请求，第一次访问本地接口获取上传的策略</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-02_23:07:10_arch_screen_70-fd449e18.png"></p>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-02_23:07:10_arch_screen_71-9f899f70.png"></p>
<ul>
<li>第二次调用oss服务 的接口进行文件上传</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-02_23:07:10_arch_screen_72-607500f5.png"></p>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-02_23:07:10_arch_screen_73-14afac34.png"></p>
<ul>
<li>可以看到上面接口调用并没有传入回调参数callback,所以接口返回了204 no content,这次我们传入回调参数callback试试，可以发现oss服务回调了我们自己定义的回调接口，并返回了相应结果。</li>
</ul>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-02_23:07:10_arch_screen_74-3439e3af.png"></p>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-02_23:07:10_arch_screen_75-43becf75.png"></p>
<p><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/obsition/2024-02-02_23:07:10_arch_screen_76-5b138bc5.png"></p>
<h2 id="项目源码地址"><a href="#项目源码地址" class="headerlink" title="#项目源码地址"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_10.html#%E9%A1%B9%E7%9B%AE%E6%BA%90%E7%A0%81%E5%9C%B0%E5%9D%80">#</a>项目源码地址</h2><p><a target="_blank" rel="noopener" href="https://github.com/macrozheng/mall-learning/tree/master/mall-tiny-09">https://github.com/macrozheng/mall-learning/tree/master/mall-tiny-09open in new window</a></p>
<h2 id="参考资料"><a href="#参考资料" class="headerlink" title="#参考资料"></a><a target="_blank" rel="noopener" href="https://www.macrozheng.com/mall/architect/mall_arch_10.html#%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99">#</a>参考资料</h2><ul>
<li><p>开通OSS服务：<a target="_blank" rel="noopener" href="https://help.aliyun.com/document_detail/31884.html?spm=a2c4g.11186623.6.566.74b87eaebrfQno">https://help.aliyun.com/document_detail&#x2F;31884.html?spm&#x3D;a2c4g.11186623.6.566.74b87eaebrfQnoopen in new window</a></p>
</li>
<li><p>创建存储空间：<a target="_blank" rel="noopener" href="https://help.aliyun.com/document_detail/31885.html?spm=a2c4g.11186623.6.567.496228bcVZUZqB">https://help.aliyun.com/document_detail&#x2F;31885.html?spm&#x3D;a2c4g.11186623.6.567.496228bcVZUZqBopen in new window</a></p>
</li>
<li><p>跨域资源共享（CORS）:<a target="_blank" rel="noopener" href="https://help.aliyun.com/document_detail/31928.html?spm=5176.11065259.1996646101.searchclickresult.4d1a5607Pf3e9i">https://help.aliyun.com/document_detail&#x2F;31928.html?spm&#x3D;5176.11065259.1996646101.searchclickresult.4d1a5607Pf3e9iopen in new window</a></p>
</li>
<li><p>服务端签名直传并设置上传回调:<a target="_blank" rel="noopener" href="https://help.aliyun.com/document_detail/31927.html?spm=a2c4g.11186623.6.1268.2c256506mNqV1t">https://help.aliyun.com/document_detail&#x2F;31927.html?spm&#x3D;a2c4g.11186623.6.1268.2c256506mNqV1t</a></p>
</li>
</ul>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta"><i class="fas fa-circle-user fa-fw"></i>文章作者: </span><span class="post-copyright-info"><a href="https://ko25891wan.gitlab.io">十一星野</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta"><i class="fas fa-square-arrow-up-right fa-fw"></i>文章链接: </span><span class="post-copyright-info"><a href="https://ko25891wan.gitlab.io/2024/01/9193a72ed815.html">https://ko25891wan.gitlab.io/2024/01/9193a72ed815.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta"><i class="fas fa-circle-exclamation fa-fw"></i>版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://ko25891wan.gitlab.io" target="_blank">小小程序员</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2024/01/0a484e1ac50b.html" title="mall整合MongoDB实现文档操作"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">mall整合MongoDB实现文档操作</div></div></a></div><div class="next-post pull-right"><a href="/2024/01/54eb55bc8ce0.html" title="mall整合RabbitMQ实现延迟消息"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">mall整合RabbitMQ实现延迟消息</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://qiniu.ko25891wan.top/%E6%97%A5%E8%AE%B0%E8%BD%AF%E4%BB%B6/%E5%A4%B4%E5%83%8F/%E7%81%B0%E5%A4%AA%E7%8B%BC.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">十一星野</div><div class="author-info__description">归途也还可爱</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">120</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">4</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">22</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://gitlab.com/ko25891wan/ko25891wan.gitlab.io"><i class="fab fa-github"></i><span>关注我</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://gitlab.com/ko25891wan/ko25891wan.gitlab.io" target="_blank" title="Github"><i class="fab fa-github" style="color: #24292e;"></i></a><a class="social-icon" href="https://gitlab.com/ko25891wan/ko25891wan.gitlab.io" target="_blank" title="Gitlab"><i class="fab fa-gitlab" style="color: #24292e;"></i></a><a class="social-icon" href="mailto:ko25891wan@outlook.com" target="_blank" title="Email"><i class="fas fa-envelope" style="color: #4a7dbe;"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%F0%9F%91%8D-%E7%9B%B8%E5%85%B3%E8%A7%86%E9%A2%91%E6%95%99%E7%A8%8B"><span class="toc-number">1.</span> <span class="toc-text">👍 相关视频教程</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#MinIO"><span class="toc-number">2.</span> <span class="toc-text">MinIO</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#OSS"><span class="toc-number">3.</span> <span class="toc-text">OSS</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#OSS%E4%B8%AD%E7%9A%84%E7%9B%B8%E5%85%B3%E6%A6%82%E5%BF%B5"><span class="toc-number">3.1.</span> <span class="toc-text">OSS中的相关概念</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#OSS%E7%9A%84%E7%9B%B8%E5%85%B3%E8%AE%BE%E7%BD%AE"><span class="toc-number">3.2.</span> <span class="toc-text">OSS的相关设置</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%BC%80%E9%80%9AOSS%E6%9C%8D%E5%8A%A1"><span class="toc-number">3.2.1.</span> <span class="toc-text">开通OSS服务</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E5%AD%98%E5%82%A8%E7%A9%BA%E9%97%B4"><span class="toc-number">3.2.2.</span> <span class="toc-text">创建存储空间</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%B7%A8%E5%9F%9F%E8%B5%84%E6%BA%90%E5%85%B1%E4%BA%AB%EF%BC%88CORS%EF%BC%89%E7%9A%84%E8%AE%BE%E7%BD%AE"><span class="toc-number">3.2.3.</span> <span class="toc-text">跨域资源共享（CORS）的设置</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9C%8D%E5%8A%A1%E7%AB%AF%E7%AD%BE%E5%90%8D%E5%90%8E%E5%89%8D%E7%AB%AF%E7%9B%B4%E4%BC%A0%E7%9A%84%E7%9B%B8%E5%85%B3%E8%AF%B4%E6%98%8E"><span class="toc-number">3.3.</span> <span class="toc-text">服务端签名后前端直传的相关说明</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%B5%81%E7%A8%8B%E7%A4%BA%E4%BE%8B%E5%9B%BE"><span class="toc-number">3.3.1.</span> <span class="toc-text">流程示例图</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%B5%81%E7%A8%8B%E4%BB%8B%E7%BB%8D"><span class="toc-number">3.3.2.</span> <span class="toc-text">流程介绍</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B4%E5%90%88OSS%E5%AE%9E%E7%8E%B0%E6%96%87%E4%BB%B6%E4%B8%8A%E4%BC%A0"><span class="toc-number">4.</span> <span class="toc-text">整合OSS实现文件上传</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%9C%A8pom-xml%E4%B8%AD%E6%B7%BB%E5%8A%A0%E7%9B%B8%E5%85%B3%E4%BE%9D%E8%B5%96"><span class="toc-number">4.1.</span> <span class="toc-text">在pom.xml中添加相关依赖</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9SpringBoot%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6"><span class="toc-number">4.2.</span> <span class="toc-text">修改SpringBoot配置文件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B7%BB%E5%8A%A0OSS%E7%9A%84%E7%9B%B8%E5%85%B3Java%E9%85%8D%E7%BD%AE"><span class="toc-number">4.3.</span> <span class="toc-text">添加OSS的相关Java配置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B7%BB%E5%8A%A0OSS%E4%B8%8A%E4%BC%A0%E7%AD%96%E7%95%A5%E5%B0%81%E8%A3%85%E5%AF%B9%E8%B1%A1OssPolicyResult"><span class="toc-number">4.4.</span> <span class="toc-text">添加OSS上传策略封装对象OssPolicyResult</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B7%BB%E5%8A%A0OSS%E4%B8%8A%E4%BC%A0%E6%88%90%E5%8A%9F%E5%90%8E%E7%9A%84%E5%9B%9E%E8%B0%83%E5%8F%82%E6%95%B0%E5%AF%B9%E8%B1%A1OssCallbackParam"><span class="toc-number">4.5.</span> <span class="toc-text">添加OSS上传成功后的回调参数对象OssCallbackParam</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#OSS%E4%B8%8A%E4%BC%A0%E6%88%90%E5%8A%9F%E5%90%8E%E7%9A%84%E5%9B%9E%E8%B0%83%E7%BB%93%E6%9E%9C%E5%AF%B9%E8%B1%A1OssCallbackResult"><span class="toc-number">4.6.</span> <span class="toc-text">OSS上传成功后的回调结果对象OssCallbackResult</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B7%BB%E5%8A%A0OSS%E4%B8%9A%E5%8A%A1%E6%8E%A5%E5%8F%A3OssService"><span class="toc-number">4.7.</span> <span class="toc-text">添加OSS业务接口OssService</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B7%BB%E5%8A%A0OSS%E4%B8%9A%E5%8A%A1%E6%8E%A5%E5%8F%A3OssService%E7%9A%84%E5%AE%9E%E7%8E%B0%E7%B1%BBOssServiceImpl"><span class="toc-number">4.8.</span> <span class="toc-text">添加OSS业务接口OssService的实现类OssServiceImpl</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B7%BB%E5%8A%A0OssController%E5%AE%9A%E4%B9%89%E6%8E%A5%E5%8F%A3"><span class="toc-number">4.9.</span> <span class="toc-text">添加OssController定义接口</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%BF%9B%E8%A1%8C%E6%8E%A5%E5%8F%A3%E6%B5%8B%E8%AF%95"><span class="toc-number">5.</span> <span class="toc-text">进行接口测试</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B5%8B%E8%AF%95%E8%8E%B7%E5%8F%96%E4%B8%8A%E4%BC%A0%E7%AD%96%E7%95%A5%E7%9A%84%E6%8E%A5%E5%8F%A3"><span class="toc-number">5.1.</span> <span class="toc-text">测试获取上传策略的接口</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%90%AF%E5%8A%A8mall-admin-web%E5%89%8D%E7%AB%AF%E9%A1%B9%E7%9B%AE%E6%9D%A5%E6%B5%8B%E8%AF%95%E4%B8%8A%E4%BC%A0%E6%8E%A5%E5%8F%A3"><span class="toc-number">5.2.</span> <span class="toc-text">启动mall-admin-web前端项目来测试上传接口</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%A1%B9%E7%9B%AE%E6%BA%90%E7%A0%81%E5%9C%B0%E5%9D%80"><span class="toc-number">6.</span> <span class="toc-text">项目源码地址</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99"><span class="toc-number">7.</span> <span class="toc-text">参考资料</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/02/c60470b9a892.html" title="Java集合使用注意事项总结">Java集合使用注意事项总结</a><time datetime="2024-02-03T04:58:22.000Z" title="发表于 2024-02-03 12:58:22">2024-02-03</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/02/81fb7a201f29.html" title="无题">无题</a><time datetime="2024-02-03T03:15:31.812Z" title="发表于 2024-02-03 11:15:31">2024-02-03</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/01/5737c1ec69a9.html" title="Wed Jan 17 2024 00:00:00 GMT+0800 (中国标准时间)">Wed Jan 17 2024 00:00:00 GMT+0800 (中国标准时间)</a><time datetime="2024-01-31T06:56:16.000Z" title="发表于 2024-01-31 14:56:16">2024-01-31</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/01/f510db7d2f19.html" title="Spring常见面试题总结">Spring常见面试题总结</a><time datetime="2024-01-31T06:55:58.000Z" title="发表于 2024-01-31 14:55:58">2024-01-31</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/01/9be065e9f288.html" title="redis 面试">redis 面试</a><time datetime="2024-01-31T06:55:55.000Z" title="发表于 2024-01-31 14:55:55">2024-01-31</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2023 - 2024 By 十一星野</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">简</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.staticfile.org/fancyapps-ui/5.0.32/fancybox/fancybox.umd.min.js"></script><script src="https://cdn.staticfile.org/instant.page/5.2.0/instantpage.min.js" type="module"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div><div id="local-search-stats-wrap"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js"></script></div></div></body></html>